// 污染预测API
import { get, post, put, del } from './request.js'
console.log('污染预测API模块加载完成')

// 污染预测API对象
export const pollutionApi = {
  // 获取工厂分析数据 - 使用化工厂控制器的接口
  getFactoryAnalysis: (params = {}) => {
    return get('/chemicalFactory/findAllFactory', params)
  },

  // 分析工厂风险 - 对应后端 /pollution-prediction/factory-analysis/{factoryId}
  analyzeFactory: (factoryId, params = {}) => {
    return post(`/pollution-prediction/factory-analysis/${factoryId}`, params)
  },

  // 预测扩散路径 - 对应后端 /pollution-prediction/diffusion-path/{factoryId}
  predictDiffusionPath: (factoryId, conditions) => {
    return post(`/pollution-prediction/diffusion-path/${factoryId}`, conditions)
  },

  // 污染预测模型 - 对应后端 /pollution-prediction/predict/{factoryId}
  predictPollution: (factoryId, hours, conditions) => {
    return post(`/pollution-prediction/predict/${factoryId}?predictionHours=${hours}`, conditions)
  },

  // 生成风险评估报告 - 对应后端 /pollution-prediction/risk-assessment/{factoryId}
  generateRiskAssessment: (factoryId, assessmentData) => {
    return post(`/pollution-prediction/risk-assessment/${factoryId}`, assessmentData)
  },

  // 生成预警机制 - 对应后端 /pollution-prediction/early-warning/{factoryId}
  generateEarlyWarning: (factoryId, currentValue, threshold) => {
    return post(`/pollution-prediction/early-warning/${factoryId}?currentLevel=${currentValue}&threshold=${threshold}`)
  },

  // 影响评估 - 对应后端 /pollution-prediction/impact-evaluation/{factoryId}
  assessImpact: (factoryId, scope, impactData) => {
    return post(`/pollution-prediction/impact-evaluation/${factoryId}?impactArea=${encodeURIComponent(scope)}`, impactData)
  },

  // 通用AI分析接口 - 对应后端 /pollution-prediction/general-analysis
  generalAnalysis: (analysisType, parameters) => {
    return post(`/pollution-prediction/general-analysis?analysisType=${encodeURIComponent(analysisType)}`, parameters)
  },

  // 获取预测结果 - 对应后端 /pollution-prediction/result/{predictionId}
  getPredictionResult: (predictionId) => {
    return get(`/pollution-prediction/result/${predictionId}`)
  },

  // 保存化工厂分析结果
  saveFactoryAnalysis: (factoryId, analysisData) => {
    return post(`/pollution-analysis/save-factory-analysis/${factoryId}`, analysisData)
  },

  // 保存扩散路径分析结果
  saveDiffusionAnalysis: (factoryId, weatherData) => {
    return post(`/pollution-analysis/save-diffusion-analysis/${factoryId}`, weatherData)
  },

  // 保存风险评估结果
  saveRiskAssessment: (factoryId, riskFactors) => {
    return post(`/pollution-analysis/save-risk-assessment/${factoryId}`, riskFactors)
  },

  // 获取分析历史记录
  getAnalysisHistory: (factoryId) => {
    return get(`/pollution-analysis/history/${factoryId}`)
  },

  // AI智能分析接口 - 基于经纬度进行智能分析
  aiSmartAnalysis: (factoryId, analysisType, locationData) => {
    return post(`/pollution-prediction/ai-smart-analysis/${factoryId}`, {
      analysisType: analysisType,
      locationData: locationData,
      timestamp: new Date().toISOString()
    })
  },

  // 批量AI分析接口 - 一次性分析多个维度
  batchAIAnalysis: (factoryId, locationData) => {
    return post(`/pollution-prediction/batch-ai-analysis/${factoryId}`, {
      locationData: locationData,
      analysisTypes: ['risk_factors', 'surrounding_environment', 'historical_accidents'],
      timestamp: new Date().toISOString()
    })
  },

  // 基于设备位置的污染预测分析 - 新增
  analyzeByLocation: (locationData) => {
    return post('/device-pollution-prediction/analyze-by-location', {
      locationData: locationData,
      timestamp: new Date().toISOString()
    })
  },

  // 获取设备附近的化工厂列表 - 新增
  getNearbyFactories: (latitude, longitude, radius = 10) => {
    return get('/device-pollution-prediction/nearby-factories', {
      latitude: latitude,
      longitude: longitude,
      radius: radius
    })
  },

  // 批量分析多个设备的污染风险 - 新增
  batchAnalyzeDevices: (devices) => {
    return post('/device-pollution-prediction/batch-analyze', {
      devices: devices,
      timestamp: new Date().toISOString()
    })
  },

  // 根据经纬度分析附近的化工厂 - 新增
  analyzeNearbyFactories: (latitude, longitude, deviceId = null) => {
    return post('/device-pollution-prediction/analyze-nearby-factories', {
      latitude: latitude,
      longitude: longitude,
      deviceId: deviceId,
      timestamp: new Date().toISOString()
    })
  },

  // 获取设备列表 - 新增
  getDeviceList: () => {
    return get('/device-pollution-prediction/device-list')
  }
}

// 默认导出
export default pollutionApi

// 调试函数
if (typeof window !== 'undefined') {
  window.pollutionApi = pollutionApi
  console.log('pollutionApi已注入到window对象:', pollutionApi)
}
